#创建网络
source /root/admin-openstack.sh
openstack network create  --share --external --provider-physical-network provider --provider-network-type flat provider

#创建子网
openstack subnet create --network provider \
--allocation-pool start={{ INSTANCE_SUBNET_START }},end={{ INSTANCE_SUBNET_END }} \
--dns-nameserver {{ INSTANCE_DNS }}  --gateway {{ INSTANCE_GATEWAY }} \
--subnet-range {{ INSTANCE_SUBNET_RANGE }} provider-subnet

#创建云主机类型
openstack flavor create --id 0 --vcpus 1 --ram 64 --disk 1 m1.nano

#创建密钥对
source /root/demo-openstack.sh
openstack keypair create --public-key ~/.ssh/id_rsa.pub mykey
openstack keypair list

#添加安全组规则
openstack security group rule create --proto icmp default
openstack security group rule create --proto tcp --dst-port 22 default

#启动实例
openstack flavor list
openstack image list


#查看可用的安全组
openstack security group list

#查看可用的网络
openstack network list

#获取网络ID
NETWORK_ID=$(openstack network list |grep provider |awk -F "[ |]+" '{print $2}')

#创建虚拟机
openstack server create --flavor m1.nano --image cirros \
--nic net-id=${NETWORK_ID} --security-group default \
--key-name mykey demo-instance

#查看虚拟机
openstack server list
